package com.zhuojy.equity.mall.admin.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuojy.equity.mall.admin.common.entity.AddressBook;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.service.AddressBookService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("address")
@RequiredArgsConstructor
@Api
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;
    /*
    分页查询
     */
    @RequestMapping("queryAddress")
    public ResultEntity queryAddress(@RequestBody AddressBook addressBook){
        try {
            IPage page=addressBookService.queryAddress(addressBook);
            return ResultEntity.OK(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.OK("操作失败");
        }
    }
    /**
     * 删除
     */
    @RequestMapping("deleteAddress")
   public ResultEntity deleteAddress(@RequestParam(value = "id" ) Integer id){
        try {
            addressBookService.deleteAddress(id);
            return ResultEntity.OK("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.OK("操作失败");
        }
   }
    /**
     * 新增修改
     */
    @RequestMapping("addAddress")
    public ResultEntity addAddress(@RequestBody AddressBook addressBook ){
        try {
            addressBookService.addAddress(addressBook);
            return ResultEntity.OK("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.OK("操作失败");
        }
    }
}
